package com.tuo51.evaluate.repositories.evaluatev2;

import com.tuo51.evaluate.domain.evaluatingV2.EvaluateV2DimensionRecommendTips;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.JpaSpecificationExecutor;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.query.Param;
import org.springframework.stereotype.Repository;

@Repository
public interface EvaluateV2DimensionRecommendTipsRepository extends JpaRepository<EvaluateV2DimensionRecommendTips, String>, JpaSpecificationExecutor<EvaluateV2DimensionRecommendTips> {

    @Query(value = "select * from tb_evaluate_dimension_recommend r where (r.channel = :channel or r.channel is null )" +
            " and (r.month is null or r.month = 0 or r.month = :month)" +
            " and r.dimensionId = :dimensionId and r.deleted = false order by r.created desc limit 1",nativeQuery = true )
    EvaluateV2DimensionRecommendTips getFirstByChannelOrChannelIsNull(@Param("dimensionId") String dimensionId,
                                                                      @Param("month") Integer month,
                                                                      @Param("channel") String channel);
}
